package com.chixing.day10.StringDemo;

/**
 * 1.String:字符串常量(适用于字符串内容不经常发生改变) (底层: final char[] value)
 * 字符串内容经常发生改变,在内存中有大量临时的String对象 占用空间,导致效率低
 * <p>
 * 2.StringBuffer:线程安全
 * <p>
 * 3.StringBuilder: 字符串内容可变 (底层: char[] value)
 * 本质:一个可动态扩容的char[]
 * 适用于字符串内容经常发生改变的场景
 * 非线程安全,适用于单线程
 */
public class StringDemo {
    public static void main(String[] args) {
        String word = "file"; //字符常量池
        word = word + "run";  //堆
        word = word.toUpperCase();

//        StringBuffer buffer = new StringBuffer();
        StringBuilder sb = new StringBuilder("hello");
        sb.append("hello");
        sb.append("testy");
        String str = sb.toString();
        System.out.println(str);

        sb.delete(0, 2);
        System.out.println(sb);
        sb.insert(3, "aaa");
        System.out.println(sb);
    }
}
